import java.util.concurrent.atomic.AtomicInteger;

public class UniqueThreadIdGenerator {

	private static final AtomicInteger uniqueId = new AtomicInteger(0);

	private static final ThreadLocal<Integer> uniqueNum = new ThreadLocal<Integer>() {
		@Override
		protected Integer initialValue() {
			return uniqueId.getAndIncrement();
		}
	};

	public static int getCurrentThreadId() {
		return uniqueId.get();
	}

	public static void main(String[] args) {
		UniqueThreadIdGenerator ut = new UniqueThreadIdGenerator();
		ut.aMethod();
	}

	static ThreadLocal tlData = new ThreadLocal();

	public void aMethod() {
		// Retrieve value.
		Object o = uniqueNum.get();
		
		System.out.println(o);

		// Set value.
		uniqueNum.set(1);
		
		System.out.println(uniqueNum.get());
	}
} // UniqueThreadIdGenerator